package com.googlecode.gwtbb.client.only.widget.form;

import com.google.gwt.user.client.ui.Image;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 3, 2009
 */
public abstract class SingletonFormDialogPushButton extends FormDialogPushButton {
	protected SingletonDialogFormStarter formStarter;

	protected SingletonFormDialogPushButton(String buttonText) {
		super(buttonText);
		initFormStarter();
	}

	protected SingletonFormDialogPushButton(Image upImage) {
		super(upImage);
		initFormStarter();
	}

	public FormStarter getFormStarter() {
		return formStarter;
	}

	public void clearForm() {
		getForm().reset();
	}

	/**
	 * Hook for subclasses to override
	 */
	public void reinitForm() {
	}

	public void restartForm() {
		clearForm();
		reinitForm();
	}

	public void startProcess() {
		formStarter.startProcess();
	}

	private void initFormStarter() {
		formStarter = new SingletonDialogFormStarter() {
			public void restartForm() {
				SingletonFormDialogPushButton.this.restartForm();
			}

			public FormWidget createForm() {
				return SingletonFormDialogPushButton.this.createForm();
			}
		};
	}
}
